﻿using System;

using System.Collections.Generic;
using System.Text;

namespace ScannerApp.ScannerWebserviceWrapper
{
    public enum ReturnCode
    {
        success,
        fail,
        loginFailed,
        noRecord,
        notInOrder,
        repeatedScan,
        noShelfCode,
        notMatchQuantity,
        notMatchShelf,
        notMatchWarehouse
    }

    

    public class BaseResult<T>
    {

        static string[] ReturnCodeMessage = 
        { 
            "成功", 
            "失败", 
            "账号错误",
            "查不到对应记录",
            "不属于此单号",
            "重复扫描",
            "查不到货位",
            "数量不匹配",
            "货位不匹配",
            "此货位没有对应的产品或批次",
            "不能跨仓库操作"

        };


        string result = string.Empty;
        string message = string.Empty;
        string failedCode = string.Empty;


        T returnValue;

        public string Result
        {
            get { return result; }
            set { result = value; }
        }

        public string Message
        {
            get { return message; }
            set { message = value; }
        }

        public string FailedCode
        {
            get { return failedCode; }
            set { failedCode = value; }
        }

        public T ReturnValue
        {
            get { return returnValue; }
            set { returnValue = value; }
        }

        public bool IsSucessful()
        {
            if (this.Result.Equals("true"))
            {
                return true;
            }
            return false;
        }

        public String getReturnCodeMessage()
        {
            try
            {
                ReturnCode code = (ReturnCode)Enum.Parse(typeof(ReturnCode), failedCode, true);
                return ReturnCodeMessage[(int)code];
            }
            catch
            {
                return failedCode;
            }
        }
    }

    
}
